<div class="aw-container-wrap" ng-app="showApp" ng-controller="showController">
    <div class="container">
        <div class="row">
            <div class="aw-content-wrap clearfix">
                <div class="col-sm-12 col-md-9 aw-main-content">
                    <!--话题-->
                    <div class="aw-mod aw-topic-bar">
                        <div class="clearfix">
                            <span class="topic-tag">
                                <a href="#" class="text"><%= article.categoryName %></a>
                            </span>
                        </div>
                    </div>
                    <!--话题-->
                    <!--问题主体-->
                    <div class="aw-mod aw-question-detail">
                        <div class="mod-head">
                            <h1><%= article.title %></h1>
                            <% if(userInfo){%>
                            <div class="operate clearfix">
                                <a href="#" class="follow btn btn-normal btn-success pull-left ">
                                    <span>关注</span> <em>|</em> <b>2</b>
                                </a>
                            </div>
                            <%}%>
                        </div>
                        <div class="mod-body">
                            <div class="content markitup-box"><%- markdown(article.linkContent) %></div>
                        </div>
                        <div class="mod-footer">
                            <div class="meta">
                                <span class="text-color-999"><%= article.create_time_ago() %></span>
                                <span class="text-color-999"><%= article.click_num %>次浏览</span>
                                <% if(userInfo && userInfo._id === article.author._id ){ %>
                                <a class="aw-add-comment text-color-999">
                                    <i class="fa fa-edit"></i>&nbsp;编辑
                                </a>
                                <a class="aw-add-comment text-color-999">
                                    <i class="fa fa-remove"></i> 删除
                                </a>
                                <% } %>
                                <div class="pull-right more-operate">
                                    <a href="#" class="text-color-999">
                                        <i class="fa fa-share-square-o"></i>&nbsp;分享
                                    </a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--问题主体-->
                    <!--回复-->
                    <%if(userInfo){%>
                    <%if(article.replies && article.replies.length > 0){%>
                    <div class="aw-mod aw-question-comment" ng-controller="reply2Controller">
                        <div class="mod-head">
                            <ul class="nav nav-tabs aw-nav-tabs active">
                                <h2 class="hidden-xs"><%= article.replies.length %>个回复</h2>
                            </ul>
                        </div>
                        <div class="mod-body aw-feed-list">
                            <% article.replies.forEach(function(reply){%>
                            <div class="aw-item" id="<%= reply._id %>">
                                <div class="mod-head">
                                    <a class="aw-user-img aw-border-radius-5 pull-right" href="/user/<%= reply.author.name %>">
                                        <img src="<%= reply.author.avatar %>">
                                    </a>
                                    <div class="title">
                                        <p>
                                            <a class="aw-user-name" href="/user/<%= reply.author.name %>"><%= reply.author.name %></a>
                                        </p>
                                    </div>
                                </div>
                                <div class="mod-body clearfix">
                                    <div class="markitup-box">
                                        <%- markdown(reply.content) %>
                                    </div>
                                </div>
                                <div class="mod-footer">
                                    <div class="meta clearfix">
                                        <span class="text-color-999 pull-right"><%= reply.create_time_ago() %></span>
                                        <span class="operate">
                                            <a class="agree">
                                                <i class="fa fa-thumbs-o-up"></i>
                                                <b class="count">0</b>
                                            </a>
                                        </span>
                                        <span class="operate">
                                            <a href="javascript:void(0)" class="aw-add-comment  reply2_btn">
                                                <i class="fa fa-commenting-o"></i>
                                                留言
                                            </a>
                                        </span>
                                    </div>
                                    <div class="aw-comment-box">
                                        <div class="aw-comment-list">
                                            <form class="reply2_form" target="/<%= article._id %>/reply" name="reply2_form" method="post" ng-submit="postForm($event)">
                                                <input type="hidden" name="reply_id" value="<%= reply._id %>">
                                                <div class="aw-comment-box-main">
                                                    <textarea class="reply_editor editor" id="reply2_editor_<%= reply._id %>" name="reply_content">

                                                    </textarea>
                                                    <div class="aw-comment-box-btn" style="display: block;">
                                                        <span class="pull-right">
                                                            <input type="submit" data-id='<%= reply._id %>' class="btn btn-mini btn-success" value="评论">
                                                            <a class="btn btn-mini btn-gray close-comment-box">取消</a>
                                                        </span>
                                                    </div>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <% })%>
                        </div>
                        <div class="mod-footer"></div>
                    </div>
                    <%}%>
                    <!--回复-->
                    <!--编辑器-->
                    <div class="aw-mod aw-replay-box" ng-controller="replyController">
                        <form id="reply_form" target="/<%= article._id %>/reply" name="reply_form" method="post" ng-submit="postForm()">
                            <div class="mod-head">
                                <a href="#" class="aw-user-name">
                                    <img src="<%= userInfo.avatar %>">
                                </a>
                                <p>
                                    <%= userInfo.name %>
                                </p>
                            </div>
                            <div class="mod-body">
                                <div class="aw-mod aw-editor-box">
                                    <div class="mod-head" style="border:0">
                                        <div class="wmd-panel">
                                            <textarea class="reply_editor" name="reply_content">

                                            </textarea>
                                        </div>
                                    </div>
                                    <div class="mod-body clearfix">
                                        <span class="pull-right">
                                            <input type="submit" value="回复" class="btn btn-normal btn-success"/>
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <!--编辑器-->
                    <%}%>
                </div>
                <div class="col-md-3 aw-side-bar hidden-xs hidden-sm">
                    <!--个人信息-->
                    <div class="aw-mod">
                        <div class="mod-head">
                            <h3>发起人</h3>
                        </div>
                        <div class="mod-body">
                            <dl>
                                <dt class="pull-left aw-border-radius-5">
                                    <a href="#"><img src="<%= article.author.avatar %>"></a>
                                </dt>
                                <dd class="pull-left">
                                    <a class="aw-user-name" href="#"><%= article.author.name %></a>
                                    <a class="pull-right">关注</a>
                                </dd>
                            </dl>
                        </div>
                        <div class="mod-footer">
                            <%= article.author.motto %>
                        </div>
                    </div>
                    <!--相关问题-->
                    <div class="aw-mod">
                        <div class="mod-head">
                            <h3>相关问题</h3>
                        </div>
                        <div class="mod-body font-size-12">
                            <%if(other_article.length > 0){%>
                            <ul>
                                <% other_article.forEach(function(article,index){%>
                                <li>
                                    <a href="/question/<%= article._id %>"><%= article.title %></a>
                                </li>
                                <% }) %>
                            </ul>
                            <% }else{ %>
                            <p>无相关问题</p>
                            <% } %>
                        </div>
                    </div>
                    <!--其他的版块-->
                    <div class="aw-mod">
                        <div class="mod-head">
                            <h3>其他的板块</h3>
                        </div>
                        <div class="mod-body">

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $('textarea.reply_editor').each(function(index,value){
        var editor = new SimpleMDE({
            element:value,
            status:[]
        })
        var $el = $(this);
        editor.render(this);
        //绑定editor
        $(this).data('editor', editor);
    })
    //继续对回复进行评论
    $('.reply2_btn').click(function(event){
        var $btn = $(event.currentTarget);
        //找到它的父级列表
        var parent = $btn.closest('.aw-item');
        //对应的表单
        var editorWrap = parent.find('.reply2_form');
        //parent.find('.aw-comment-list').prepend(editorWrap);
        //找到所有的输入框
        var textarea = editorWrap.find('textarea.editor');
        //找到所对应的用户
        var user = $btn.closest('.aw-item').find('.aw-user-name').text().trim();
        var editor = textarea.data('editor');
        var cm = editor.codemirror;
        editorWrap.show('fast',function(){
            if(cm.getValue().indexOf('@' + user) < 0){
                editor.value('@' + user + ' ');
            }
        })
    })
</script>
